import VueI18n from 'vue-i18n'
import { Locale } from 'vant'
import { setStorage } from '../libs/utils/storage'
// 引入公共国际化语言，文件单独的则单独引入
import EN from './en_US'
import zh_CN from './zh-CN'
// elementui国际化
import enLocale from 'vant/es/locale/lang/en-US'
import zhLocale from 'vant/es/locale/lang/zh-CN'
import { setDefaultLang } from '../libs/utils/locale'


Vue.use(VueI18n)
let defaultLang = setDefaultLang() || 'zh-CN'
let messages = {
    'en-US': {
      ...EN,
      ...enLocale
    },
    'zh-CN': {
      ...zh_CN,
      ...zhLocale
    }
  }
Locale.use(defaultLang, messages[defaultLang])

const i18n = new VueI18n({
  locale: defaultLang,
  fallbackLocale: 'zh-CN',
  silentTranslationWarn: true,
  messages
})

export const changeLocale = (lang) => {
  setStorage('localeLang', lang)
  Locale.use(lang, messages[lang])
  i18n.locale = lang
}

export default i18n
